function PDInterFormData (pDoc){
	this.m_pDoc = pDoc;
	this.m_nVersion = null;
	this.m_arrFields = [];				// Fields
	this.m_bNeedAppearances = false;	// NeedAppearances
	this.m_nSigFlags = 0;				// SigFlags
	this.m_arrCO = [];					// CO
	this.m_resourceDic = null;			// DR
	this.m_structDA = null;				// DA
	this.m_nAlign = 0;					// Q
	
	this.parseInterFormData = function (rd){
		var hasInterForm = rd.readUint8();
		if (hasInterForm != 0){
			this.m_nVersion = rd.readUint16();
			var fieldsCount = rd.readUint32();
			if (fieldsCount != 0){
				for (var i = 0; i < fieldsCount; ++ i){
					//get field dictionary
					var formField = new PDFormField();
					formField.parseFormField(rd);
					this.m_arrFields[i] = formField;
				}
			}
			
			this.m_bNeedAppearances = rd.readUint8();
			this.m_nSigFlags = rd.readInt32();
			var nCOCount = rd.readInt32();
			if (nCOCount != 0){
				for (var i = 0; i < nCOCount; ++ i){
					//get field dictionary
					var formField = new PDFormField();
					formField.parseFormField(rd);
					this.m_arrCO[i] = formField;
				}
			}
			var nUseFlag = rd.readUint8();		// DR
			if (nUseFlag != 0){
				this.m_resourceDic = {};
				this.m_resourceDic.m_nFontCount = rd.readUint32();
				if (this.m_resourceDic.m_nFontCount != 0){
					for (var i = 0; i < this.m_resourceDic.nFontCount; ++ i){
						var font = new FontInfo(this.m_pDoc, this.m_pDoc.m_imgPath);
						font.ParseFromBin(rd);
						this.m_resourceDic.m_arrFont[i] = font;
					}
				}
			}
			var nHasDA = rd.readUint8();
			if (nHasDA != 0){
				this.m_structDA = {};
				this.m_structDA.m_strFont = getStringValue(rd);
				this.m_structDA.m_strColor = getStringValue(rd);
				this.m_structDA.m_strMatrix = getStringValue(rd);
			}
			this.m_nAlign = rd.readUint8();
		}	
	};
	
	this.getFieldByid = function(id){
		for(var i = 0;i < this.m_arrFields.length;i++){
			if(this.m_arrFields[i].m_nID == id){
				return this.m_arrFields[i];
			}
		}
	};
}

//////////////////////////////////////////////////////////
//FormField
//////////////////////////////////////////////////////////
function PDFormField(){
	this.m_nID = null;
	this.m_strFieldTypeName = null;
	this.m_nType = null;
	this.m_strFullName = null;	//T
	this.m_strTU = null;
	this.m_strTM = null;
	this.m_nFieldFlag = null;
	this.m_strValue = null;
	this.m_strDefValue = null;
	this.m_strDefStyle = null;
	this.m_strRichText = null;
	this.m_addAction = null;
	this.m_addEntries = {};
	
	this.parseFormField = function (rd){
		this.m_nID = rd.readInt32();
		
		if (this.m_nID == 94){
			var a = 0;
		}
		
		this.m_strFieldTypeName = getStringValue(rd);
		
		this.m_nType = rd.readUint8();
		
		this.m_strFullName = getWideStringValue(rd);
		
		this.m_strTU = getWideStringValue(rd);
		
		this.m_strTM = getWideStringValue(rd);
		
		this.m_nFieldFlag = rd.readInt32();
		
		this.m_strValue = getWideStringValue(rd);
		
		this.m_strDefValue = getWideStringValue(rd);
		
		this.m_strDefStyle = getStringValue(rd);
		
		this.m_strRichText = getWideStringValue(rd);
		
		var nUseFlag = rd.readUint8();
		if (nUseFlag != 0){
			this.m_addAction = {};
			this.m_addAction.m_nActionCount = rd.readUint8();
			this.m_addAction.m_arrAction = [];
			for (var i = 0; i < this.m_addAction.m_nActionCount; ++ i){
				this.m_addAction.m_arrAction[i] = {};
				parseAction(this.m_addAction.m_arrAction[i], rd);
			}
		}
		
		this.praseAddFieldEntries(this.m_strFieldTypeName, rd);
	};
	
	this.praseAddFieldEntries = function (fieldtypeName, rd){
		if (fieldtypeName == "Btn"){
			this.m_addEntries.m_nOptCount = rd.readInt32();
			if (this.m_addEntries.m_nOptCount != 0){
				this.m_addEntries.m_arrOpt = [];
				for (var i = 0; i < this.m_addEntries.m_nOptCount; ++ i){
					this.m_addEntries.m_arrOpt[i] = getStringValue(rd);
				}
			}
			
			//console.log("Btn " + this.m_addEntries.m_nOptCount);
		}else if (fieldtypeName == "Tx"){
			this.m_addEntries.m_nMaxLen = rd.readInt32();
			
			//console.log("Tx " + this.m_addEntries.m_nMaxLen);
		}else if (fieldtypeName == "Ch"){
			this.m_addEntries.m_nOptCount = rd.readInt32();
			if (this.m_addEntries.m_nOptCount != 0){
				this.m_addEntries.m_arrOpt = [];
				for (var i = 0; i < this.m_addEntries.m_nOptCount; ++ i){
					this.m_addEntries.m_arrOpt[i] = getWideStringValue(rd);
				}
			}
			
			this.m_addEntries.m_nTI = rd.readInt32();
			
			this.m_addEntries.m_nICount = rd.readInt32();
			if (this.m_addEntries.m_nICount != 0){
				this.m_addEntries.m_arrI = [];
				for (var i = 0; i < this.m_addEntries.m_nICount; ++ i){
					this.m_addEntries.m_arrI[i] = rd.readInt32();
				}
			}
			
			//console.log("Ch " + this.m_addEntries.m_arrI);
		}else if (fieldtypeName == "Sig"){
			
		}
	};
}

//////////////////////////////////////////////////////////
//FormControl
//////////////////////////////////////////////////////////
function PDFormControl(pdPage){
	this.m_pdPage = pdPage;
	this.m_nType = null;
	this.m_pBBox = [];
	this.m_bChecked = null;
	this.m_bDefChecked = null;
	this.m_nFieldID = null;		// Parent
	this.m_nAnnotID = null;	// widget annot
	
	this.parseFormControl = function(rd){
		this.m_nFieldID = rd.readInt32();
		
		this.m_nType = rd.readUint8();
		
		this.m_pBBox[0] = rd.readFloat32();
		this.m_pBBox[1] = rd.readFloat32();
		this.m_pBBox[2] = rd.readFloat32();
		this.m_pBBox[3] = rd.readFloat32();
		
		this.m_bChecked = rd.readUint8();
		
		this.m_bDefChecked = rd.readUint8();
		
		this.m_nAnnotID = rd.readUint32();
		//console.log("control's AnnotID: " + this.m_nAnnotID);
	};
}